﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;

/// <summary>
///  By Jimmy Shan!
/// </summary>
public class DBbase
{
    public SqlConnection Conn;

    /// 弹出JavaScript小窗?
    /// </summary>
    /// <param name="js">�窗口信息</param>
    public static void Alert(string message)
    {
        #region
        string js = @"<Script language='JavaScript'>
                    alert('" + message + "');</Script>";
        HttpContext.Current.Response.Write(js);

        #endregion
    }

    public DBbase()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    #region  数据库联接开?

    //�打开
    private void OpenSqlConnection()
    {
        StringBuilder constr = new StringBuilder();

        constr.Append("server=" + ConfigurationManager.AppSettings["IP"] + ";");
        constr.Append("uid=" + ConfigurationManager.AppSettings["Uid"] + ";");
        constr.Append("pwd=" + ConfigurationManager.AppSettings["Pwd"] + ";");
        constr.Append("database=" + ConfigurationManager.AppSettings["DBName"]);

        Conn = new SqlConnection(constr.ToString());
        Conn.Open();
    }
    //关闭
    private void CloseSqlConnection()
    {
        Conn.Close();
        Conn.Dispose();
    }

    #endregion

    public void returnCon()
    {
        OpenSqlConnection();
    }

    //绑定HTML下拉列表
    public void BandObjHTML(HtmlSelect aHtmlSelect, string Sql, string aTextField, string aValueField)
    {
        Cls_Db Db = new Cls_Db();
        aHtmlSelect.DataSource = Db.GetDataSet(Sql);
        aHtmlSelect.DataTextField = aTextField;
        aHtmlSelect.DataValueField = aValueField;
        aHtmlSelect.DataBind();
    }
    //绑定WEB控件下拉列表
    public void BandObjWeb(DropDownList aHtmlSelect, string Sql, string aTextField, string aValueField)
    {
        Cls_Db Db = new Cls_Db();
        aHtmlSelect.DataSource = Db.GetDataSet(Sql);
        aHtmlSelect.DataTextField = aTextField;
        aHtmlSelect.DataValueField = aValueField;
        aHtmlSelect.DataBind();
    }


    
}
